<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Login_model extends Base_Model {
    /* -- Call the constructor -- */

    var $tbl_name = 'member';

    function __construct() {
        parent::__construct();
    }

    function get_by_email_password($email = '', $password = '') {
        if ($email != '' && $password != '') {
            $this->db->where('email', $email);
            $this->db->where('password', $password);
            $query = $this->db->get($this->tbl_name);
            return $query->row_array();
        } else {
            return false;
        }
    }

    function update_login($mem_id) {
        if ($mem_id) {
            $last_login = date('Y-m-d H:i:s');
            $_SESSION['member']['last_login'] = $last_login;
            $this->db->set('count_login', 'count_login+1', FALSE);
            $this->db->set('last_login', $last_login);
            $this->db->where(array('id' => $mem_id));
            $this->db->update('member');
        }
    }
    
    function get_by_email($email){
        if (!empty($email)) {
            $this->db->where('email', $email);
            $query = $this->db->get('member');
            return $query->row_array();
        } else {
            return false;
        }
    }

}

